package com.you.concurrent.future;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

public class CompletableFutureDemo {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CompletableFuture.runAsync(() -> {
            System.out.println(Thread.currentThread().getName() + "---------step 1--------");
            try {
                Thread.sleep(5000L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).thenRun(() -> {
            System.out.println(Thread.currentThread().getName() + "---------step 2--------");
        });

        CompletableFuture.runAsync(() -> {
        }).thenAccept(resultA -> {
            System.out.println(resultA);
        });


        CompletableFuture.supplyAsync(() -> "resultA").thenAccept(resultA -> {
            System.out.println(resultA);
        });

        CompletableFuture.runAsync(() -> {
        }).thenApply(resultA -> "resultB");

//        CompletableFuture.runAsync(() -> {
//            System.out.println("---------step 1--------");
//            try {
//                Thread.sleep(5000L);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
//        }).thenAccept();
        Thread.sleep(10000L);
        System.out.println("---------main print--------");
    }
}
